package com.example.pojo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class BillResponse {
    private Long customerId;
    private String customerName;
    private String customerIdCard;
    private List<BillItem> billItemList;
    private BigDecimal discountPrice;
    private BigDecimal totalPrice;

    public static BillResponse convertFromBill(Bill bill, String customerName, String customerIdCard) {
        BillResponse billResponse = new BillResponse();
        billResponse.customerId = bill.getCustomerId();
        billResponse.customerName = customerName;
        billResponse.customerIdCard = customerIdCard;
        billResponse.billItemList = bill.getBillItemList();
        BigDecimal discountPrice = BigDecimal.valueOf(0);
        for (BillItem billItem : billResponse.billItemList) {
            BigDecimal discount = discountPrice.add(billItem.getPrice().subtract(billItem.getDiscountedPrice()));
            discountPrice.add(discount);
        }
        billResponse.totalPrice = bill.getTotal_price();
        return billResponse;
    }
}
